'use strict';

const Controller = require('egg').Controller;
const atob = require('atob');

class UserController extends Controller {
    async getAvat() {
        const {
            ctx
        } = this;
        // ctx.cookie.csrfToken
        console.log(ctx.header.csrftoken);
        
        const id =Number(this.decodeID(ctx.header.csrftoken))
        const res = await this.service.user.getUserAvat(id)
        ctx.body = {
            code:200,
            avatar: res['avatar']
        }
    }


    /**
     * 解析token中的id
     * @return {String}
     **/
    decodeID(base64) {
        const decode = atob(base64);
        return decode.split("@")[1];
    }
}

module.exports = UserController;